﻿using Sasc.PV.BLL.Annotation;
using Sasc.PV.DAL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Transactions;

namespace Sasc.PV.BLL.ZhuDing
{
    [GongXu("烧结", typeof(ZhuDingCheJianManagement))]
    public class ZhuDingShaoJieGongXu : ZhuDingGongXuBase
    {
        #region DeleteShaoJieCollections
        public bool DeleteShaoJieCollections(string idList)
        {
            try
            {
                using (var transaction = new TransactionScope())
                {                    
                    // Delete ShaoJieYunXing
                    var shaoJieYunXingSql = new StringBuilder();
                    shaoJieYunXingSql.Append("DELETE FROM PvZDShaoJieYunXing ");
                    shaoJieYunXingSql.Append(" WHERE ShaoJieCollectionID in (" + idList + ")  ");
                    DbHelperSQL.ExecuteSql(shaoJieYunXingSql.ToString());

                    // Delete ShaoJie
                    var shaoJieIDsSqlBuilder = new StringBuilder();
                    shaoJieIDsSqlBuilder.Append("SELECT ID FROM PvZDShaoJie ");
                    shaoJieIDsSqlBuilder.Append(" WHERE ShaoJieCollectionID in (" + idList + ")  ");

                    var shaoJieIDDataTable = DbHelperSQL.GetDataTable(shaoJieIDsSqlBuilder.ToString());
                    var shaoJieIDsBuilder = new StringBuilder();
                    if (shaoJieIDDataTable != null && shaoJieIDDataTable.Rows.Count > 0)
                    {
                        foreach (DataRow row in shaoJieIDDataTable.Rows)
                        {
                            if(shaoJieIDsBuilder.Length>0)
                                shaoJieIDsBuilder.Append(",");
                            shaoJieIDsBuilder.Append(row[0]);
                        }
                    }
                    if (shaoJieIDsBuilder.Length > 0)
                        DeleteGongXuRecList(shaoJieIDsBuilder.ToString());

                    new PvZDShaoJieCollection().DeleteList(idList);
                    WriteRiZhi(string.Format("删除烧结运转记录：{0}", idList));

                    transaction.Complete();
                }
            }
            catch (Exception e)
            {
                return false;
            }

            return true;
        }
        #endregion
    }
}
